package com.tb.controller;

import com.tb.model.Follow;
import com.tb.model.Message;
import com.tb.service.FollowService;
import com.tb.service.MessageService;
import com.tb.util.MyConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @description: 关注相关
 * @author: wangguichun
 * @create: 2018-04-17 21:32
 **/

@Controller
@RequestMapping("follow")
public class FollowController {
    @Autowired
    private FollowService followService;
    @Autowired
    private MessageService messageService;

    @RequestMapping("add")
    @ResponseBody
    public void add(Follow follow){
        followService.addFollowRecord(follow);
        Message message = new Message();
        message.setFromId(follow.getFromId());
        message.setToId(follow.getToId());
        message.setType(MyConstant.ACT_FOLLOW);
        message.setObjecId(follow.getFromId());
        message.setTime(new Date().getTime());
        messageService.addMessage(message);
    }

    @RequestMapping("remove")
    @ResponseBody
    public void remove(Follow follow){
        followService.removeFollowRecord(follow);
    }





}
